package com.core.dao.jdbcmysql;

import com.core.bean.Goods;
import com.core.dao.IGoodsDao;
import com.core.utils.GsonUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

public class GoodsDao extends JdbcBase implements IGoodsDao {
    @Override
    public int add(Goods entity) throws Exception {
        String Sql = "INSERT INTO `lct_goods` VALUES(?,?,?,?,?) ";
        Connection connection = getConnection();
        PreparedStatement ps = connection.prepareStatement(Sql);
        try {

            ps.setString(1, entity.getId());
            ps.setString(2, entity.getPid());
            ps.setObject(3, entity.getPrice());
            ps.setString(4, GsonUtils.toJsonStr(entity.getProperty()));
            ps.setInt(5, entity.getStatus());
            return ps.executeUpdate();
        } catch (Exception e) {
            throw e;
        } finally {
            ps.close();
            connection.close();
        }
    }

    @Override
    public int remove(String id) throws Exception {
        return 0;
    }

    @Override
    public int modify(Goods entity) throws Exception {
        return 0;
    }

    @Override
    public Goods findEntityById(String id) throws Exception {
        return null;
    }

    @Override
    public List<Goods> findByPropertyId(String pid) {
        return null;
    }
}
